﻿using System.Diagnostics.CodeAnalysis;

namespace zijian666.AnyExtensions;

/// <summary>
/// 值类型拓展方法
/// </summary>
public static class StructExtensions
{
    /// <summary>
    /// 判断值为空或默认值
    /// </summary>
    public static bool IsNullOrDefault<T>([NotNullWhen(false)] this T? value)
        where T : struct => value is null || value.Value.Equals(default(T));

    /// <summary>
    /// 判断值不是空或默认值
    /// </summary>
    public static bool NotNullOrDefault<T>([NotNullWhen(true)] this T? value)
        where T : struct => value.HasValue && !value.Value.Equals(default(T));
}